/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-09-02 22:47:16
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-09-03 22:05:40
 * @FilePath: /metaverse-manage/app/controller/Contact.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Controller } from 'egg';
import { response } from '../utils/common';
import { initContact, updateContact } from '../entity/Contact';

export default class ContactController extends Controller {
  // 查询所有
  public async queryAllContacts() {
    const { ctx } = this;
    const result = await ctx.service.contact.queryAllContacts();
    ctx.body = response(result);
  }
  public async queryContactById() {
    const { ctx } = this;
    const { id } = ctx.params;
    const result = await ctx.service.contact.queryContactById(Number(id));
    ctx.body = response(result);
  }
  public async createContact() {
    const { ctx } = this;
    const contact = initContact({ ...ctx.request.body });
    const result = await ctx.service.contact.createContact(contact);
    ctx.body = response(result);
  }
  public async updateContact() {
    const { ctx } = this;
    const { id } = ctx.params;
    const contact = updateContact({ ...ctx.request.body });
    const result = await ctx.service.contact.updateContact(Number(id), contact);
    ctx.body = response(result);
  }
  public async removeContact() {
    const { ctx } = this;
    const { id } = ctx.params;
    const result = await ctx.service.contact.removeContact(Number(id));
    ctx.body = response(result);
  }

}
